import "./type"

interface Person{
   name:string,
   age:number,
   height:number,
   address?:string
}
// 约束对象
let user:Person={
    name:"liz",
    age:12,
    height:123,
    // address:"山东济南"
}
// 约束函数
interface PersonT{
    name:string,
    age:number,
    height:number,
    address?:string,
    // sayHello:()=>void
    sayHello():void
 }
// 约束函数
 let userT:PersonT = {
    name:'dyn',
    age:12,
    height:12,
    address:"山东济南",
    sayHello:()=>{
        console.log("hello")
    }
 }
//  别名约束函数
// type condition = (num:number)=>boolean
type condition = { // 大扩号相当于定界符
    (n:number):boolean // 具体内容
}
function sum(numbers:number[],callback:condition):number{
    let s = 0;
    numbers.forEach((item,index)=>{
         if(callback(item)){
            s+=item
         }
    })
    return s
}
let sum1 =sum([2,3,56,3,5],(n)=>n%2==0)
console.log(sum1)
// 接口约束别名
interface Condition {
    (n:number):boolean
}

// 接口可以继承
interface A{
    T1:string
}
interface B extends A{
    T2:number
}
interface C extends A,B{
    T3:number,
    // T1:Boolean
}
let U:B={
    T1:"liz",
    T2:12
}
let U2:C={
    T1:"liz",
    T2:12,
    T3:13
}
// 使用类型别名也可以实现类似的组合效果，通过& 叫做交叉类型
// 区别 子接口不能覆盖父接口
interface Duck {
    sound:"gagaga",
    swin():void
}

let person ={
    name:"伪装",
    age:12,
    sound:"gagaga" as "gagaga",
    swin(){
        console.log("swin")
    }
}
let duck:Duck=person